/********************************************/
// Creation History
// --------------------------------------------------------------
//	Company:			HTHK
//	NAME:				GroupServlet.java
//    Title   :			operate A Group Record such as:Create,Update,Delete
//	FUNCTION:
//	BY:				Poly Li
//	DATE:				14/01/2004
// --------------------------------------------------------------
/*********************************************/
// Copyright (c) 2002 HTHK

package tss.group;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import tss.common.DBServlet2;

import com.ffpc.sql.DataException;
import com.ffpc.struts.StrutsMessage;
import com.ffpc.util.DateFormatter;

public class GroupServlet extends DBServlet2 {

	@Override
	protected String perform(HttpServletRequest request,
			HttpServletResponse response, StrutsMessage message) throws DataException {

		// New A Form Action
		String action = new String(request.getParameter("formAction"));

		// New A StaffProject Record
		GroupBean group = GroupProcess.createBean();

		// Get A Group Record
		group.setGroup_name(request.getParameter("group_name"));
		group.setComments(request.getParameter("comments"));

		// Insert
		if (action.trim().equalsIgnoreCase("Create")) {
			group.setCreate_date(DateFormatter.format(this.getDate()));
			group.setCreate_by(getUser().getUser_id());
			if (GroupProcess.insert(this.getConnection(), group) > 0)
				message.setMessage("Save successfully.");
			else
				message.setMessage("Save failure");
		}
		// Update
		else if (action.trim().equalsIgnoreCase("Update")) {
			// for delete all exist record
			group.setUpd_date(DateFormatter.format(this.getDate()));
			group.setUpd_by(getUser().getUser_id());
			if (GroupProcess.update(this.getConnection(), group) > 0)
				message.setMessage("Save successfully.");
			else
				message.setMessage("Save failure.");
		}
		// Delete
		else if (action.trim().equalsIgnoreCase("Delete")) {

			if (GroupProcess.delete(this.getConnection(), group) > 0)
				message.setMessage("Delete successfully.");
			else
				message.setMessage("Delete failure.");

		} else {
			message.setMessage("No action mapped!");
		}
		return "tss/group/GroupSearch.jsp";

	}
}
